package com.eascs.admin.dataType.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.admin.common.controller.BaseViewController;
import com.eascs.admin.dataType.entity.O2ODataTypeEntity;
import com.eascs.admin.dataType.service.O2ODataTypeService;
import com.eascs.admin.dataType.vo.O2ODataTypeEntityVo;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;

@Controller
@RequestMapping("/dataType")
public class O2ODataTypeController extends BaseViewController {
	
	@Autowired
	O2ODataTypeService o2ODataTypeService;
	
	@SuppressWarnings("unused")
	@RequestMapping("/index")
	public String index(O2ODataTypeEntityVo vo) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "addDataT");
		vo.setPageSize(10);
		String url = "/dataType/index";
		if (null != vo) {
			String dtCode = vo.getDtCode() == null ? "" : vo.getDtCode();
			String dtName = vo.getDtName() == null ? "" : vo.getDtName();
			url = UrlUtil.appendUrl(url, "dtCode", dtCode);
			url = UrlUtil.appendUrl(url, "dtName", dtName);
			url = url + "&pageIndex=";
		} else {
			url = url + "&pageIndex=";
		}
		Button detail = ButtonHelper.createOpenButton("管理资料类型", "/dataType/detail?dtId=");
		Button edit = ButtonHelper.createAjaxButton("修改", "/rDataType/editDtHtml?dtId=");
		Button delete = ButtonHelper.createAjaxConfirmButton("删除", "/rDataType/deleteDt?dtId=");
		detail.setPermissionCode("manage_dataType");
		edit.setPermissionCode("update_dataType");
		delete.setPermissionCode("del_dataType");
		Button buttons[] = new Button[] { edit, detail,delete };
		PageResult<Object[]> pageResult = o2ODataTypeService.findO2ODateTypeByPage(vo);
		String titles[] = { "类型编号", "分类名称", "排序", "子类型数" };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(buttons);
		ViewContext.put("vo", vo);
		ViewContext.put("paginationInfo", paginationInfo);
		return "datatype/index";
	}

	@RequestMapping("/detail")
	public String detail(O2ODataTypeEntityVo vo) {
		vo.setPageSize(Integer.MAX_VALUE);
		PageResult<Object[]> pageResult = o2ODataTypeService.findO2ODateTypeChildByPage(vo);
		String titles[] = { "类型编号", "名称", "排序", "资料要求", "格式" };
		Button edit = ButtonHelper.createAjaxButton("修改", "/rDataType/editdtcHtml?dtChildId=");
		Button delete = ButtonHelper.createAjaxConfirmButton("删除", "/rDataType/deletedtc?dtChildId=");
		Button buttons[] = new Button[] { edit,delete };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(buttons);
		O2ODataTypeEntity o2ODateTypeEntity = o2ODataTypeService.findO2ODataTypeById(vo.getDtId());
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", o2ODateTypeEntity);
		return "datatype/detail";
	}
}
